package com.yunyouyi.grabtickets.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunyouyi.grabtickets.entity.Ticket;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TicketMapper extends BaseMapper<Ticket> {
    @Update("UPDATE ticket SET stock = stock - 1 WHERE train_id = #{trainId} AND stock > 0")
    int updateStock(@Param("trainId") String trainId);
    @Select("SELECT * FROM ticket WHERE train_id = #{trainId} LIMIT 1")
    Ticket selectByTrainId(@Param("trainId") String trainId);
}